package com.ruoyi.web.controller.wx;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.controller.util.JacksonUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("wx/user")
public class WxUserController {

    @Resource
    ISysUserService sysUserService;

    @PostMapping("/update")
    public AjaxResult update(@RequestBody String body){
        Long userId = SecurityUtils.getUserId();
        if (userId == null){
            return AjaxResult.error(-1,"用户未登录");
        }
        String mobile = JacksonUtil.parseString(body,"mobile");
        String avatar = JacksonUtil.parseString(body,"avatar");
        String nickname = JacksonUtil.parseString(body,"nickname");
        SysUser sysUser = new SysUser();
        sysUser.setUserId(userId);
        sysUser.setPhonenumber(mobile);
        sysUser.setAvatar(avatar);
        sysUser.setNickName(nickname);
        return AjaxResult.success(sysUserService.updateUser(sysUser));
    }
}
